package main.daydayup.day0726;

/**
 * 整数反转:
 * 要看的点：
 * 1.整数越界的问题
 * 2.利用整数取模来以此作为反转的顺序
 * @author: kejl
 * @create: 2020-07-26 22:57
 */
public class IntegerNumReverse {


    public static void main(String[] args) {

        int result  = reverse(123332423);
        System.out.println(result);

    }


        public static int reverse(int x) {
            int rev = 0;
            while (x != 0) {
                int pop = x % 10;
                x /= 10;
                if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0;
                if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0;
                rev = rev * 10 + pop;
            }
            return rev;
        }



}
